library(magrittr)
library(tidyverse)
library(Seurat)
library(readxl)
library(cowplot)
library(colorblindr)
library(viridis)
library(progeny)

theme_cowplot2 <- function(...) {
  theme_cowplot(font_size = 12, ...) %+replace%
    theme(strip.background = element_blank(),
          plot.background = element_blank())
}
theme_set(theme_cowplot2())
coi <- params$cell_type
cell_sort <- params$cell_sort
cell_type_major <- params$cell_type_major
louvain_resolution <- params$louvain_resolution

1 Cluster markers

1.1 Major Ovarian.cancer.cell markers for cell assign

### load all data ---------------------------------

helper_f <- function(x) ifelse(is.na(x), "", x)
markers_v6 <- yaml::read_yaml("/home/uhlitzf/spectrum_tme/_data/small/signatures/hgsc_v6_major.yaml")

helper_f2 <- function(x) select(unnest(enframe(x, "subtype", "gene"), cols = gene), gene, subtype)
markers_v6_super <- lapply(yaml::read_yaml("/home/uhlitzf/spectrum_tme/_data/small/signatures/hgsc_v6_super.yaml"), helper_f2)

clrs <- yaml::read_yaml("/home/uhlitzf/spectrum_tme/_data/small/signatures/hgsc_v6_colors.yaml") %>% 
  lapply(function(x) map_depth(x, vec_depth(x)-2, unlist))

names(clrs$patient_id) <- str_remove_all(names(clrs$patient_id), "SPECTRUM-OV-")

meta_tbl <- read_excel("_data/small/MSK SPECTRUM - Single cell RNA-seq_v6.xlsx", sheet = 2) %>% 
  mutate(patient_id = str_remove_all(patient_id, "SPECTRUM-OV-")) %>% 
  filter(therapy == "pre-Rx")

signature_tbl <- read_tsv("_data/small/mutational_signatures_summary.tsv") %>% 
  mutate(patient_id = str_remove_all(patient_id, "SPECTRUM-OV-")) %>% 
  select(patient_id, consensus_signature) %>% 
  bind_rows(tibble(patient_id = unique(sort(meta_tbl$patient_id[!(meta_tbl$patient_id %in% .$patient_id)])), consensus_signature = "NA")) %>% 
  mutate(consensus_signature = ordered(consensus_signature, levels = names(clrs$consensus_signature))) %>%
  arrange(consensus_signature)

seu_obj <- read_rds("/work/shah/uhlitzf/data/SPECTRUM/freeze/v5/Ovarian.cancer.cell_highqc.rds")

myfeatures <- c("UMAP_1", "UMAP_2", "umapharmony_1", "umapharmony_2", "sample", "RNA_snn_res.0.1", "RNA_snn_res.0.2", "RNA_snn_res.0.3", "doublet", "nCount_RNA", "nFeature_RNA", "percent.mt", "doublet_score")

plot_data <- as_tibble(FetchData(seu_obj, myfeatures)) %>% 
  left_join(select(meta_tbl, sample = isabl_id, patient_id, tumor_supersite, tumor_subsite, sort_parameters, therapy), 
            by = "sample") %>% 
  mutate(patient_id = str_remove_all(patient_id, "SPECTRUM-OV-"),
         RNA_snn_res.0.1 = as.character(RNA_snn_res.0.1),
         RNA_snn_res.0.2 = as.character(RNA_snn_res.0.2),
         RNA_snn_res.0.3 = as.character(RNA_snn_res.0.3),
         tumor_supersite = ordered(tumor_supersite, levels = names(clrs$tumor_supersite))) %>% 
  mutate(cell_id = colnames(seu_obj)) %>% 
  left_join(signature_tbl, by = "patient_id")

patient_id <- sort(unique(plot_data$patient_id))

WFDC2, CD24, CLDN3, KRT7, KRT8, KRT17, KRT18, KRT19, EPCAM, WT1, CLDN4, MSLN, FOLR1, MUC1

1.2 Subtype currated markers

markers_v6_super[[coi]] %>% 
  group_by(subtype) %>% 
  mutate(rank = row_number(gene)) %>% 
  spread(subtype, gene) %>% 
  mutate_all(.funs = helper_f) %>% 
  formattable::formattable()
rank Ciliated.cell.1 Ciliated.cell.2 Cycling.cancer.cell.1 Cycling.cancer.cell.2 doublet.Other Endometrial.cell Secretory.cell.1 Secretory.cell.2 Secretory.cell.3 Secretory.cell.4 Secretory.cell.5 Secretory.cell.6
1 C20orf85 KRT14 CENPF ATP5MC1 AGR2 HP KRT7 AGR2 FBXO32 AKAP12 CLDN1 CXCL10
2 CAPS KRT16 HMGB2 PHB CRISP3 OBP2A PLCG2 CRISP3 GAS6 DCDC2 CLDN16 IFIT1
3 CAPSL KRT5 MKI67 SNF8 IGFBP7 PAEP SCGB2A1 OVGP1 MTSS1 MMP7 EREG IFIT2
4 PIFO MMP7 PTTG1 SNRPD1 ITM2B PTGDS SLPI SCGB1A1 SAMHD1 TSPAN1 NDUFB5 IFIT3
5 TPPP3 SLURP1 TOP2A TMEM106C SPARCL1 SERINC2 SST SCGB3A1 TFF3 TSPAN18 ISG15
6 TFF3 TFF3 MX1

1.3 Subtype cluster markers

marker_tbl <- read_tsv("/work/shah/uhlitzf/data/SPECTRUM/freeze/v5/Ovarian.cancer.cell_highqc_markers_02.tsv")

## Hypergeometric test --------------------------------------

test_set <- marker_tbl %>% 
  group_by(cluster) %>% 
  filter(!str_detect(gene, "^RPS|^RPL")) %>% 
  slice(1:50) %>% 
  mutate(k = length(cluster)) %>% 
  ungroup %>%
  select(cluster, gene, k) %>% 
  mutate(join_helper = 1) %>% 
  group_by(cluster, join_helper, k) %>%
  nest(test_set = gene)

markers_doub_tbl <- markers_v6 %>% 
  enframe("subtype", "gene") %>% 
  filter(!(subtype %in% unique(c(coi, cell_type_major)))) %>% 
  unnest(gene) %>% 
  group_by(gene) %>% 
  filter(length(gene) == 1) %>% 
  mutate(subtype = paste0("doublet.", subtype)) %>% 
  bind_rows(tibble(subtype = "Mito.high", gene = grep("^MT-", rownames(seu_obj), value = T)))

ref_set <- markers_v6_super[[coi]] %>% 
  bind_rows(markers_doub_tbl) %>% 
  group_by(subtype) %>% 
  mutate(m = length(gene),
         n = length(rownames(seu_obj))-m,
         join_helper = 1) %>% 
  group_by(subtype, m, n, join_helper) %>%
  nest(ref_set = gene)

hyper_tbl <- test_set %>% 
  left_join(ref_set, by = "join_helper") %>% 
  group_by(cluster, subtype, m, n, k) %>%
  do(q = length(intersect(unlist(.$ref_set), unlist(.$test_set)))) %>%
  mutate(pval = 1-phyper(q = q, m = m, n = n, k = k)) %>%
  ungroup %>%
  mutate(qval = p.adjust(pval, "BH"),
         sig = qval < 0.01)

# hyper_tbl %>% 
#   group_by(subtype) %>% 
#   filter(any(qval < 0.01)) %>%
#   ggplot(aes(subtype, -log10(qval), fill = sig)) +
#   geom_bar(stat = "identity") +
#   facet_wrap(~cluster) +
#   coord_flip()
  
low_rank <- str_detect(unique(hyper_tbl$subtype), "doublet")
subtype_lvl <- c(sort(unique(hyper_tbl$subtype)[!low_rank]), sort(unique(hyper_tbl$subtype)[low_rank]))
  
cluster_label_tbl <- hyper_tbl %>% 
  mutate(subtype = ordered(subtype, levels = subtype_lvl)) %>% 
  arrange(qval, subtype) %>%
  group_by(cluster) %>% 
  slice(1) %>% 
  mutate(subtype = ifelse(sig, as.character(subtype), paste0("unknown_", cluster))) %>% 
  select(cluster, cluster_label = subtype) %>% 
  ungroup %>% 
  mutate(cluster_label = make.unique(cluster_label, sep = "_"))

seu_obj$cluster_label <- unname(deframe(cluster_label_tbl)[as.character(unlist(seu_obj[[paste0("RNA_snn_res.", louvain_resolution)]]))])
plot_data$cluster_label <- seu_obj$cluster_label

marker_sheet <- marker_tbl %>% 
  left_join(cluster_label_tbl, by = "cluster") %>% 
  group_by(cluster_label) %>% 
  filter(!str_detect(gene, "^RPS|^RPL")) %>% 
  slice(1:50) %>% 
  mutate(rank = row_number(-avg_logFC)) %>% 
  select(cluster_label, gene, rank) %>% 
  spread(cluster_label, gene) %>% 
  mutate_all(.funs = helper_f)

formattable::formattable(marker_sheet)
rank Ciliated.cell.1 Ciliated.cell.1_1 Cycling.cancer.cell.1 Cycling.cancer.cell.1_1 Cycling.cancer.cell.2 doublet.Fibroblast doublet.Monocyte doublet.Monocyte_1 doublet.Other doublet.Plasma.cell Endometrial.cell Secretory.cell.1 Secretory.cell.1_1 Secretory.cell.2 Secretory.cell.2_1 Secretory.cell.5 Secretory.cell.6 unknown_13
1 C20orf85 CFAP126 HIST1H4C CENPF PHB TAGLN IGKC APOE CRISP3 IGLC2 PAEP SCGB2A1 S100A9 OVGP1 SPINK1 CLDN16 CXCL10 NTS
2 CAPS DNALI1 TUBA1B PTTG1 SNF8 TPM2 IGLC2 NDUFA4L2 IGFBP7 IGKC HP DAPL1 SLPI CRISP3 CXCL1 EREG ISG15 CALB1
3 TPPP3 PIFO PCLAF UBE2S ATP5MC1 LGALS1 IGLC3 DMKN ITM2B CRIP1 PTGDS SCGB1D2 TACSTD2 PLCG2 SFTA2 PCLAF IFIT3 MAOB
4 RSPH1 FAM183A ATAD2 HMGB2 MEG3 ACTA2 IGHG1 LINC00665 SCGB1D2 HIST1H4C SCGB2A1 SNHG19 LCN2 CCND1 CXCL8 HIST1H1A IFIT1 SOX18
5 C9orf24 CASC1 MKI67 TPX2 TMBIM4 CALD1 SPP1 COX6B1 EIF4A2 IGLC3 OBP2A SNHG8 S100A10 PTMS CST6 RAC3 MX1 CDH2
6 C5orf49 RSPH1 H2AFZ ASPM RARRES2 MT1H SRGN GPI EPB41L4A-AS1 TOP2A PCP4 KCNQ1OT1 IGFBP3 SNHG9 CXCL3 CTHRC1 IFIT2 CHST1
7 PIFO LRRIQ1 PCNA MKI67 UBE2Z NMU C1QB C19orf53 CIRBP ATP1B3 S100A4 GABPB1-AS1 GPRC5A DSTN CAMK2N1 TMEM100 PARP14 MFSD3
8 TMEM190 C20orf85 TK1 CDC20 PDK2 RAB32 CCL4 PEPD ASRGL1 DEFB1 SERINC2 KRT17 PEG10 SPP1 MMP23B IFI6 RSPO3
9 FAM183A DNAAF1 TUBB TOP2A ITM2C SELENOP GNLY PSENEN PIK3R1 SNRPF CRABP1 KRT7 YWHAE UPK1B RRM2 IFI44L PIR
10 C1orf194 C5orf49 CKS1B CKS2 SLC35B1 ANXA3 RGS1 PDCD5 EEF1A1 HMGN1 FOLR1 RARRES1 APOLD1 AGR2 SYT10 GBP4 AL589182.1
11 CETN2 C9orf24 TYMS CCNB1 PCP4 MT1G IGHG3 USP11 SNHG7 KLK5 SCGB1D1 KRT19 CDC20 CAV1 PHOX2A STAT1 MHENCR
12 AGR3 AGR3 DUT BIRC5 XPOT CDKN2A C1QA TMEM147 NPM1 IGHG1 HLA-DQA1 VEGFA EPB41L2 CXCL5 CNIH2 TNFSF10 AP000527.1
13 TXN C1orf194 HMGB2 ARL6IP1 ZCRB1 CCT5 LYZ IGF2.1 TPT1 NNMT HLA-DRB5 SOX4 MYL12B GNG11 C1QTNF12 GBP1 SIX1
14 ODF3B ARMC3 TOP2A LGALS1 SPOP VIM CCL3 FBXO2 BTF3 IGF1 SNCG MMP7 PTPRA ADM TMEM178A XAF1 PRRX2
15 CAPSL CFAP45 UBE2C UBE2C ZNF652 YBX1 KRT6A NPW FAU ATP5ME HLA-DQB1 NDRG1 RBMX AC092069.1 AC008771.1 SOD2 PREX2
16 CFAP126 EFCAB1 SMC4 JPT1 HOXB4 AKAP12 IGFL2-AS1 CLDN9 EHF HMGB1 AC007906.2 S100A6 PABPC4 CXCL2 MTRNR2L1 IDO1 PYCR3
17 TUBA1A TPPP3 DEK CEP55 HOXB2 COTL1 TYROBP CPVL KCNMA1 PCSK1N HSPA1A FTL METAP2 PTGS2 CENPM OAS1 FHL1
18 MORN2 ZMYND10 MCM3 CCNB2 FXYD1 IGFBP2 FCER1G MFAP4 CAPS C4orf48 CHI3L1 CRYAB VIM TNFRSF11B CENPH IFI27 MPPED2
19 C11orf88 PPIL6 HELLS PTMS TWF1 FHL2 PTPRC GSTM3 AR RARRES1 CYP4B1 ANXA1 MYL6B RHOBTB3 CENPK TNFAIP2 F3
20 DNAAF1 ENKUR STMN1 NMU C2orf40 NDUFS6 FCGR3A HMGA2 UGT2B17 ATP5PF HLA-DRA SLC2A1 RBM8A VGLL3 PRTFDC1 RSAD2 ACSM3
21 TUBB4B CDC20B CDK1 CDKN3 KAT7 PCDH10 CCL4L2 FXYD1 GYPC HIST1H1C DEFB1 TFPI2 SNHG19 MALL POMC IFIH1 MMD
22 FOXJ1 SPATA17 NUSAP1 TUBA1B AC008124.1 EEF1B2 CCL5 GFRA1 EEF2 S100A10 HLA-B FTH1 WBP11 EFEMP1 GPT PSMB9 NDP
23 ZMYND10 CAPSL MCM7 NUSAP1 COMP UCHL1 LAPTM5 ZFP14 EIF1 DEK S100A1 CD55 PPT1 WNT2 MELTF-AS1 IL32 AP001528.2
24 LRRIQ1 TEKT2 CENPF H2AFZ LHX1 MYH9 C1QC HIST1H2BC ERP27 UBE2S HLA-DPA1 C19orf33 BRD9 KRT13 SPC24 CXCL11 APOO
25 IGFBP7 CFAP44 CLSPN KPNA2 SEMA3E MYL12A IL7R COL9A3 TMEM98 MT1E CITED4 S100A11 ST13 IL20RA MYBL2 DDX58 GBP5
26 IK TEKT1 MCM4 HMGB1 CRTAC1 SUB1 ITGB2 MXRA8 SORBS2 NUSAP1 NPDC1 TNFRSF12A SNHG25 ANKRD1 OXTR SAMD9 RHBDD3
27 EFCAB1 CFAP54 UBE2T HMGN2 FBXO2 ANXA5 CD52 TIMP3 HOXB4 MKI67 PRSS33 EMP1 AMD1 LINC01127 AC025159.1 RNF213 SAMD10
28 DYDC2 CFAP43 MYBL2 ECT2 LEMD3 MYL9 IGHGP BGN PART1 CCL4 GMPR PI3 SNRPB CXCL6 AFAP1-AS1 IRF1 NRARP
29 EFHC1 SPEF1 SMC2 ANP32E HOXB-AS1 CLDN7 CD14 IGF2BP3 FYB2 SMC1B HLA-DRB1 ANXA2 NAP1L1 RAB42 ASF1B WARS LINC02303
30 DNALI1 FAM81B HMGB1 CENPE LGR5 S100A10 AIF1 CA9 FRMD4A IGHG3 GADD45B MAL2 SNRPB2 GABRP PTPRS CCL20 SLC28A2
31 AL357093.2 EFCAB10 RAD51AP1 STMN1 LMO3 CD151 FYB1 CPS1 SYNE1 RGS1 MESP1 S100A2 PA2G4 XAGE2 CALML5 B2M SOX2
32 C9orf116 CFAP46 TPX2 HMMR IGF2BP1 MT1M CCL3L1 FBN2 ALDH1A1 PTMA FAM107A TAGLN NSA2 C5orf46 LINC01436 CXCL8 ANKRD6
33 CEP126 ROPN1L ZWINT HMGB3 IL11RA CD47 NKG7 STC2 PDE4D C1QB MFGE8 CAMK2N1 NMT1 ABLIM3 HOMER1 ISG20 MAN1B1-DT
34 SNTN CFAP73 RRM2 TROAP COL9A3 FLNA ALOX5AP PLOD1 HSPB6 SLC16A8 CYBA LDHA TMCO1 COL4A4 F2R TAP1 KCNMB4
35 CCDC170 C7orf57 NASP KIF20B MDM1 IL32 SAMSN1 NRN1 HOXB6 SRGN IRX3 AKAP12 WDR70 COL8A1 SEMA6A LAP3 TBX2
36 PERP SPAG8 CENPW SMC4 TSPOAP1 MYL12B CD2 PAGE2 KAZALD1 APOC1 MYL9 TGM2 IGFBP3 GDF7 PTGER1 OAS3 ABO
37 ROPN1L WDR38 CENPX CKS1B CLDN9 PSMB6 IGHG4 HCST SYT10 FAM111B PRDX5 ITGB8 TBCA CCL20 FZD8 HLA-B BMPR1B-DT
38 CKB WDR49 TMPO NUCKS1 PRELP ACTR3 GPR183 HOXA10-AS TGFB2 AIF1 NUPR1 BNIP3 KRT81 AC245041.2 HACD1 IFI16 FES
39 TEKT2 ZBBX E2F1 H2AFV C12orf56 PDCD6 LSP1 FGFR3 SH3BP5 IGHG4 CLDN3 SLC40A1 TTYH1 BMP4 SALL4 LY6E SLC8A1
40 C9orf135 DRC1 RANBP1 RAD21 AC090673.1 SRI CD3D CPXM2 MAP3K1 TYROBP SLC26A2 SQSTM1 HMGB1 ALPP CENPN PLSCR1 AL713998.1
41 SPA17 WDR63 DNMT1 NCAPD2 FXYD6 NDUFS5 CD37 HOTAIRM1 AKR1C3 CCL5 HOMER3 CD24 ATP5ME CDA SOX15 HLA-A ZNF252P-AS1
42 GDF15 CFAP157 MAD2L1 DLGAP5 FAM117A COX4I1 IL1B NXPH4 DPP4 TCHH HLA-DMA EZR AGR3 MARCH10 CDC6 NFKBIA AC064807.1
43 TEKT1 DYNLRB2 TMEM106C AURKA CCDC170 EEF1D GMFG KRBOX1 ACSM3 C1QA MGLL FAM3C TMA7 GPR87 FANCD2 HLA-C CPED1
44 PSENEN C6orf118 HIST1H1D CENPW COL6A2 TPM3 MS4A7 LRIG3 SLITRK5 FCGR3A HLA-DPB1 MUC4 SFRP1 DKK1 CCR10 IFI44 THAP7-AS1
45 WDR38 RSPH4A ASPM NEK2 CYYR1 UQCRH CD7 SDC2 PREX2 DDIT4L ETV4 ATP1A1 TPT1 SLC16A12 CACNG4 OAS2 UFSP1
46 LRRC23 DNAH12 FANCI TUBB4B CRYGD CXCL12 MS4A6A TMEM147-AS1 CMBL FLG ATP6V0B CLDN1 ANO1 SULT1E1 MND1 BIRC3 EFHC2
47 ARMC3 TTLL9 BIRC5 PLK1 GPC6 PDCL2 LST1 AEBP1 CCND2 CD2 UCP2 P4HA1 MEG3 THBD CASC10 HERC5 SYT12
48 MLF1 MAP3K19 ORC6 CENPA FGF17 NPTX1 GZMB FGF11 CCDC170 PTPRC SPDEF CST6 CCND2 MSX2 BHMT2 UBE2L6 TBX3
49 ERICH3 MORN5 DTYMK MAD2L1 PLXNA4 MUC12 GZMA KCNG1 IL18 IGHGP JUND SLC16A3 CD177 GATA3 AC144450.1 SAMD9L TMEM135
50 CFAP45 STMND1 TUBB4B TUBA1C TBX2-AS1 HPD CD53 TGFB1 SKAP1 TRBC1 EMP2 NEAT1 PEG3 CYP2W1 CGAS CXCL2 AL161669.3
write_tsv(marker_sheet, paste0("/work/shah/uhlitzf/data/SPECTRUM/freeze/v6/", coi, "_marker_sheet.tsv"))

2 Clusters

2.1 sizes

enframe(sort(table(seu_obj$cluster_label))) %>% 
  mutate(name = ordered(name, levels = rev(name))) %>% 
  ggplot() +
  geom_bar(aes(name, value), stat = "identity") +
  theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5)) +
  labs(y = c("#cells"), x = "cluster")

2.2 UMAP

alpha_lvl <- ifelse(nrow(plot_data) < 20000, 0.2, 0.1)
pt_size <- ifelse(nrow(plot_data) < 20000, 0.2, 0.05)

common_layers_disc <- list(  
  geom_point(size = pt_size, alpha = alpha_lvl),
  NoAxes(),
  guides(color = guide_legend(override.aes = list(size = 2, alpha = 1))),
  labs(color = "")
)

common_layers_cont <- list(  
  geom_point(size = pt_size, alpha = alpha_lvl),
  NoAxes(),
  scale_color_gradientn(colors = viridis(9)),
  guides(color = guide_colorbar())
)

ggplot(plot_data, aes(umapharmony_1, umapharmony_2, color = cluster_label)) + 
  common_layers_disc +
  #facet_wrap(~therapy) +
  ggtitle("Sub cluster")

3 Filtering out doublet and mito high clusters

3.1 UMAP

my_subtypes <- names(clrs$cluster_label[[coi]])

my_subtypes <- c(my_subtypes, unlist(lapply(paste0("_", 1:3), function(x) paste0(my_subtypes, x)))) %>% .[!str_detect(., "doublet")]

cells_to_keep <- colnames(seu_obj)[seu_obj$cluster_label %in% my_subtypes]
# seu_obj_sub <- subset(seu_obj, cells = cells_to_keep)
# seu_obj_sub <- RunUMAP(seu_obj_sub, dims = 1:20, reduction = "harmony", reduction.name = "umapharmony", reduction.key = "umapharmony_")
# seu_obj_sub$cluster_label <- seu_obj$cluster_label[colnames(seu_obj) %in% colnames(seu_obj_sub)]
# write_rds(seu_obj_sub, paste0("/work/shah/uhlitzf/data/SPECTRUM/freeze/v6/", coi, "_processed_filtered.rds"))
seu_obj_sub <- read_rds(paste0("/work/shah/uhlitzf/data/SPECTRUM/freeze/v6/", coi, "_processed_filtered.rds"))

plot_data_sub <- as_tibble(FetchData(seu_obj_sub, c(myfeatures, "cluster_label"))) %>% 
  left_join(select(meta_tbl, sample = isabl_id, patient_id, tumor_supersite, tumor_subsite, sort_parameters, therapy), 
            by = "sample") %>% 
  mutate(patient_id = str_remove_all(patient_id, "SPECTRUM-OV-"),
         tumor_supersite = ordered(tumor_supersite, levels = names(clrs$tumor_supersite))) %>% 
  mutate(cell_id = colnames(seu_obj_sub),
         cluster_label = ordered(cluster_label, levels = my_subtypes),
         ) %>% 
  left_join(signature_tbl, by = "patient_id")
  
if (cell_sort == "CD45+") {
plot_data_sub <- filter(plot_data_sub, sort_parameters != "singlet, live, CD45-", !is.na(tumor_supersite))
}

if (cell_sort == "CD45-") {
plot_data_sub <- filter(plot_data_sub, sort_parameters != "singlet, live, CD45+", !is.na(tumor_supersite))
}

ggplot(plot_data_sub, aes(umapharmony_1, umapharmony_2, color = cluster_label)) + 
  common_layers_disc +
  # scale_color_manual(values = clrs$cluster_label[[coi]])
  #facet_wrap(~cluster_label) +
  ggtitle("Sub cluster") 

ggplot(plot_data_sub, aes(umapharmony_1, umapharmony_2, color = patient_id)) + 
  common_layers_disc +
  ggtitle("Patient") +
  # facet_wrap(~therapy) +
  scale_color_manual(values = clrs$patient_id)

ggplot(plot_data_sub, aes(umapharmony_1, umapharmony_2, color = tumor_supersite)) + 
  # geom_point(aes(umapharmony_1, umapharmony_2), 
  #            color = "grey90", size = 0.01, 
  #            data = select(plot_data_sub, -tumor_supersite)) +
  common_layers_disc +
  ggtitle("Site") +
  # facet_wrap(~therapy) +
  scale_color_manual(values = clrs$tumor_supersite)

write_tsv(select(plot_data_sub, cell_id, everything(), -UMAP_1, -UMAP_2, -contains("RNA_")), paste0("/work/shah/uhlitzf/data/SPECTRUM/freeze/v6/", coi, "_embedding.tsv"))

3.2 add module scores and pathway scores

signature_modules <- read_excel("_data/small/signatures/SPECTRUM v5 sub cluster markers.xlsx", sheet = 2, skip = 1, range = "M2:P100") %>% 
  gather(module, gene) %>% 
  na.omit() %>% 
  group_by(module) %>% 
  do(gene = c(.$gene)) %>% 
  {setNames(.$gene, .$module)}

signature_modules$ISG.module <- c("CCL5", "CXCL10", "IFNA1", "IFNB1", "ISG15", "IFI27L2", "SAMD9L")

## compute expression module scores
for (i in 1:length(signature_modules)) {
  seu_obj_sub <- AddModuleScore(seu_obj_sub, features = signature_modules[i], name = names(signature_modules)[i])
  seu_obj_sub[[names(signature_modules)[i]]] <- seu_obj_sub[[paste0(names(signature_modules)[i], "1")]]
  seu_obj_sub[[paste0(names(signature_modules)[i], "1")]] <- NULL
  print(paste(names(signature_modules)[i], "DONE"))
}
## [1] "CD8.Cytotoxic DONE"
## [1] "CD8.Dysfunctional DONE"
## [1] "CD8.Naive DONE"
## [1] "CD8.Predysfunctional DONE"
## [1] "ISG.module DONE"
## compute progeny scores
progeny_list <- seu_obj_sub@assays$RNA@data[VariableFeatures(seu_obj_sub),] %>% 
  as.matrix %>% 
  progeny %>% 
  as.data.frame %>% 
  as.list

names(progeny_list) <- make.names(paste0(names(progeny_list), ".pathway"))

for (i in 1:length(progeny_list)) {
  seu_obj_sub <- AddMetaData(seu_obj_sub, metadata = progeny_list[[i]], 
                             col.name = names(progeny_list)[i])
}

write_rds(seu_obj_sub, paste0("/work/shah/uhlitzf/data/SPECTRUM/freeze/v6/", coi, "_processed_filtered.rds"))

3.3 marker heatmap

marker_top_tbl <- marker_sheet[,-1] %>% 
  slice(1:10) %>% 
  as.list %>% 
  .[!str_detect(names(.), "doublet")] %>% 
  enframe("cluster_label_x", "gene") %>% 
  unnest(gene)

plot_data_markers <- as_tibble(FetchData(seu_obj_sub, c("cluster_label", myfeatures, unique(marker_top_tbl$gene)))) %>% 
  gather(gene, value, -c(1:(length(myfeatures)+1))) %>% 
  left_join(select(meta_tbl, sample = isabl_id, patient_id, tumor_supersite, tumor_subsite, sort_parameters, therapy), 
            by = "sample") %>% 
  mutate(patient_id = str_remove_all(patient_id, "SPECTRUM-OV-"),
         tumor_supersite = ordered(tumor_supersite, levels = names(clrs$tumor_supersite))) %>% 
  mutate(cluster_label = ordered(cluster_label, levels = my_subtypes)) %>% 
  group_by(cluster_label, gene) %>% 
  summarise(value = mean(value, na.rm = T)) %>% 
  group_by(gene) %>% 
  mutate(value = scales::rescale(value)) %>% 
  left_join(marker_top_tbl, by = "gene") %>% 
  mutate(cluster_label_x = ordered(cluster_label_x, levels = rev(names(clrs$cluster_label[[coi]]))))

ggplot(plot_data_markers) +
  geom_tile(aes(gene, cluster_label, fill = value)) +
  theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5)) +
  facet_grid(~cluster_label_x, scales = "free", space = "free") +
  scale_fill_gradientn(colors = viridis(9)) +
  labs(fill = "Scaled\nexpression") +
  theme(aspect.ratio = 1,
        axis.line = element_blank(),
        axis.ticks = element_blank(),
        axis.title = element_blank())

# ggsave(paste0("_fig/002_marker_heatmap_", coi, ".pdf"), width = nrow(marker_top_tbl)/6, height = 5)

3.4 composition

3.4.1 per site

comp_site_tbl <- plot_data_sub %>%
  filter(!is.na(tumor_supersite)) %>% 
  group_by(cluster_label, tumor_supersite) %>%
  tally %>%
  group_by(tumor_supersite) %>%
  mutate(nrel = n/sum(n)*100) %>%
  ungroup

pnrel_site <- ggplot(comp_site_tbl) +
  geom_bar(aes(tumor_supersite, nrel, fill = cluster_label),
           stat = "identity", position = position_stack()) +
  scale_y_continuous(expand = c(0, 0)) +
  theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5)) +
  # scale_fill_manual(values = clrs$cluster_label[[coi]]) +
  labs(fill = "Cluster", y = "Fraction [%]", x = "")

pnabs_site <- ggplot(comp_site_tbl) +
  geom_bar(aes(tumor_supersite, n, fill = cluster_label),
           stat = "identity", position = position_stack()) +
  scale_y_continuous(expand = c(0, 0)) +
  theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5)) +
  # scale_fill_manual(values = clrs$cluster_label[[coi]]) +
  labs(fill = "Cluster", y = "# cells", x = "") 

plot_grid(pnabs_site, pnrel_site, ncol = 2, align = "h")

# ggsave(paste0("_fig/02_deep_dive_", coi, "_comp_site.pdf"), width = 8, height = 4)

3.4.2 per sample

comp_tbl_sample_sort <- plot_data_sub %>% 
  group_by(tumor_subsite, tumor_supersite, patient_id, consensus_signature, therapy, cluster_label) %>% 
  tally %>% 
  group_by(tumor_subsite, tumor_supersite, patient_id, consensus_signature, therapy) %>% 
  mutate(nrel = n/sum(n)*100,
         nsum = sum(n),
         log10n = log10(n),
         label_supersite = "Site",
         label_mutsig = "Signature",
         label_therapy = "Rx") %>% 
  ungroup %>% 
  arrange(desc(therapy), tumor_supersite) %>% 
  mutate(tumor_subsite_rx = paste0(tumor_subsite, "_", therapy)) %>% 
  mutate(tumor_subsite = ordered(tumor_subsite, levels = unique(tumor_subsite)),
         tumor_subsite_rx = ordered(tumor_subsite_rx, levels = unique(tumor_subsite_rx))) %>% 
  arrange(patient_id) %>% 
  mutate(label_patient_id = ifelse(as.logical(as.numeric(fct_inorder(as.character(patient_id)))%%2), "Patient1", "Patient2"))

sample_id_x_tbl <- plot_data_sub %>% 
  mutate(sort_short_x = cell_sort) %>% 
  distinct(patient_id, sort_short_x, tumor_subsite, therapy, sample) %>% 
  unite(sample_id_x, patient_id, sort_short_x, tumor_subsite, therapy) %>% 
  arrange(sample_id_x)

comp_tbl_sample_sort %>% 
  mutate(sort_short_x = cell_sort) %>% 
  unite(sample_id_x, patient_id, sort_short_x, tumor_subsite_rx) %>% 
  select(sample_id_x, cluster_label, n, nrel, nsum) %>% 
  left_join(sample_id_x_tbl, by = "sample_id_x") %>% 
  write_tsv(paste0("/work/shah/uhlitzf/data/SPECTRUM/freeze/v6/", coi, "_subtype_compositions.tsv"))
ybreaks <- c(500, 1000, 2000, 4000, 6000, 8000, 10000, 15000, 20000)

max_cells_per_sample <- max(comp_tbl_sample_sort$nsum)
ymaxn <- ybreaks[max_cells_per_sample < ybreaks][1]

comp_plot_wrapper <- function(y = "nrel", switch = NULL) {
  if (y == "nrel") ylab <- paste0("Fraction\nof cells [%]")
  if (y == "n") ylab <- paste0("Number\nof cells")
  p <- ggplot(comp_tbl_sample_sort, 
              aes_string("tumor_subsite_rx", y, fill = "cluster_label")) + 
    facet_grid(~patient_id, space = "free", scales = "free", switch = switch) +
    coord_cartesian(clip = "off") + 
    # scale_fill_manual(values = clrs$cluster_label[[coi]]) + 
    theme(axis.text.x = element_blank(),
          axis.title.y = element_text(angle = 0, vjust = 0.5, hjust = 0.5, 
                                      margin = margin(0, -0.4, 0, 0, unit = "npc")),
          axis.ticks.x = element_blank(),
          axis.title.x = element_blank(),
          axis.line.x = element_blank(),
          strip.text.y = element_blank(),
          strip.text.x = element_blank(),
          strip.background.y = element_blank(),
          strip.background.x = element_blank(),
          plot.margin = margin(0, 0, 0, 0, "npc")) + 
    labs(x = "",
         y = ylab) +
    guides(fill = FALSE)
  if (y == "nrel") p <- p + 
    geom_bar(stat = "identity") +
    scale_y_continuous(expand = c(0, 0), 
                       breaks = c(0, 50, 100), 
                       labels = c("0", "50", "100"))
  if (y == "n") p <- p + 
    geom_bar(stat = "identity", position = position_stack()) +
    scale_y_continuous(expand = c(0, 0), 
                       breaks = c(0, ymaxn/2, ymaxn),
                       limits = c(0, ymaxn),
                       labels = c("", ymaxn/2, ymaxn)) +
    expand_limits(y = c(0, ymaxn)) +
    theme(panel.grid.major.y = element_line(linetype = 1, color = "grey90", size = 0.5))
  return(p)
} 

common_label_layers <- list(
  geom_tile(color = "white", size = 0.15),
  theme(axis.text.x = element_blank(),
        axis.ticks = element_blank(),
        axis.title.x = element_blank(),
        axis.line.x = element_blank(),
        strip.text = element_blank(),
        strip.background = element_blank(),
        plot.margin = margin(0, 0, 0, 0, "npc")),
  scale_y_discrete(expand = c(0, 0)),
  labs(y = ""),
  guides(fill = FALSE),
  facet_grid(~patient_id, 
             space = "free", scales = "free")
)

comp_label_site <- ggplot(distinct(comp_tbl_sample_sort, tumor_subsite_rx, therapy, tumor_supersite, label_supersite, patient_id), 
       aes(tumor_subsite_rx, label_supersite, 
           fill = tumor_supersite)) + 
  scale_fill_manual(values = clrs$tumor_supersite) +
  common_label_layers

comp_label_rx <- ggplot(distinct(comp_tbl_sample_sort, tumor_subsite_rx, therapy, tumor_supersite, label_therapy, consensus_signature, patient_id), 
       aes(tumor_subsite_rx, label_therapy, 
           fill = therapy)) + 
  scale_fill_manual(values = c(`post-Rx` = "gold3", `pre-Rx` = "steelblue")) +
  common_label_layers

comp_label_mutsig <- ggplot(distinct(comp_tbl_sample_sort, tumor_subsite_rx, therapy, tumor_supersite, label_mutsig, consensus_signature, patient_id), 
       aes(tumor_subsite_rx, label_mutsig, 
           fill = consensus_signature)) + 
  scale_fill_manual(values = clrs$consensus_signature) +
  common_label_layers

patient_label_tbl <- distinct(comp_tbl_sample_sort, patient_id, .keep_all = T)

comp_label_patient_id <- ggplot(patient_label_tbl, aes(tumor_subsite_rx, label_patient_id)) + 
  scale_fill_manual(values = clrs$consensus_signature) +
  geom_text(aes(tumor_subsite_rx, label_patient_id, label = patient_id)) +
  facet_grid(~patient_id, 
             space = "free", scales = "free") +
  coord_cartesian(clip = "off") + 
  theme_void() +
  theme(strip.text = element_blank(),
        strip.background = element_blank(),
        plot.margin = margin(0, 0, 0, 0, "npc"))

hist_plot_wrapper <- function(x = "nrel") {
  if (x == "nrel") {
    xlab <- paste0("Fraction of cells [%]")
    bw <- 5
  }
  if (x == "log10n") {
    xlab <- paste0("Number of cells")
    bw <- 0.2
  }
  p <- ggplot(comp_tbl_sample_sort) +
    ggridges::geom_density_ridges(
      aes_string(x, "cluster_label", fill = "cluster_label"), color = "black",
      stat = "binline", binwidth = bw, scale = 3) +
    facet_grid(label_supersite~., 
               space = "free", scales = "free") +
    # scale_fill_manual(values = clrs$cluster_label[[coi]]) + 
    theme(axis.text.y = element_blank(),
          axis.ticks.y = element_blank(),
          axis.title.y = element_blank(),
          axis.line.y = element_blank(),
          strip.text = element_blank(),
          strip.background = element_blank(),
          plot.margin = margin(0, 0, 0, 0, "npc")) +
    scale_x_continuous(expand = c(0, 0)) +
    scale_y_discrete(expand = c(0, 0)) +
    guides(fill = FALSE) +
    labs(x = xlab)
  if (x == "log10n") p <- p + expand_limits(x = c(0, 3)) + 
    scale_x_continuous(expand = c(0, 0), 
                       labels = function(x) parse(text = paste("10^", x)))
  return(p)
}

pcomp1 <- comp_plot_wrapper("n")
pcomp2 <- comp_plot_wrapper("nrel")

pcomp_grid <- plot_grid(comp_label_patient_id, 
                        pcomp1, pcomp2, 
                        comp_label_site, comp_label_rx, comp_label_mutsig,
                        ncol = 1, align = "v", 
                        rel_heights = c(0.15, 0.33, 0.33, 0.06, 0.06, 0.06))

phist1 <- hist_plot_wrapper("log10n")

pcomp_hist_grid <- ggdraw() +
  draw_plot(pcomp_grid, x = 0.01, y = 0, width = 0.85, height = 1) +
  draw_plot(phist1, x = 0.87, y = 0.05, width = 0.12, height = 0.8)

pcomp_hist_grid

# ggsave(paste0("_fig/02_composition_v6_",coi,".pdf"), pcomp_hist_grid, width = 10, height = 2)

3.4.3 site specific cluster enrichment

comp_tbl_z <- comp_tbl_sample_sort %>% 
  filter(therapy == "pre-Rx",
         !(tumor_supersite %in% c("Ascites", "Other"))) %>% 
  group_by(patient_id, cluster_label) %>% 
  arrange(patient_id, cluster_label, nrel) %>% 
  mutate(rank = row_number(nrel),
         z_rank = scales::rescale(rank)) %>% 
  mutate(mean_nrel = mean(nrel, na.rm = T),
         sd_nrel = sd(nrel, na.rm = T),
         z_nrel = (nrel - mean_nrel) / sd_nrel) %>% 
  ungroup()

ggplot(comp_tbl_z) +
  geom_boxplot(aes(tumor_supersite, z_nrel, color = tumor_supersite), 
               outlier.shape = NA) +
  geom_point(aes(tumor_supersite, z_nrel, color = tumor_supersite), position = position_jitter(), size = 0.1) +
  facet_grid(~cluster_label, scales = "free_x", space = "free_x") +
  theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5),
        aspect.ratio = 5) +
  scale_color_manual(values = clrs$tumor_supersite)

ggplot(comp_tbl_z) +
  geom_boxplot(aes(tumor_supersite, z_rank, color = tumor_supersite), 
               outlier.shape = NA) +
  geom_point(aes(tumor_supersite, z_rank, color = tumor_supersite), position = position_jitter(), size = 0.1) +
  facet_grid(~cluster_label, scales = "free_x", space = "free_x") +
  theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5),
        aspect.ratio = 5) +
  scale_color_manual(values = clrs$tumor_supersite)

4 session info

devtools::session_info()
## ─ Session info ───────────────────────────────────────────────────────────────
##  setting  value                       
##  version  R version 3.6.2 (2019-12-12)
##  os       Debian GNU/Linux 10 (buster)
##  system   x86_64, linux-gnu           
##  ui       X11                         
##  language (EN)                        
##  collate  en_US.UTF-8                 
##  ctype    en_US.UTF-8                 
##  tz       Etc/UTC                     
##  date     2020-12-05                  
## 
## ─ Packages ───────────────────────────────────────────────────────────────────
##  package      * version    date       lib
##  ape            5.3        2019-03-17 [2]
##  assertthat     0.2.1      2019-03-21 [2]
##  backports      1.1.10     2020-09-15 [1]
##  bibtex         0.4.2.2    2020-01-02 [2]
##  Biobase        2.46.0     2019-10-29 [2]
##  BiocGenerics   0.32.0     2019-10-29 [2]
##  bitops         1.0-6      2013-08-17 [2]
##  broom          0.7.2      2020-10-20 [1]
##  callr          3.4.2      2020-02-12 [1]
##  caTools        1.17.1.4   2020-01-13 [2]
##  cellranger     1.1.0      2016-07-27 [2]
##  cli            2.0.2      2020-02-28 [1]
##  cluster        2.1.0      2019-06-19 [3]
##  codetools      0.2-16     2018-12-24 [3]
##  colorblindr  * 0.1.0      2020-01-13 [2]
##  colorspace   * 1.4-2      2019-12-29 [2]
##  cowplot      * 1.0.0      2019-07-11 [2]
##  crayon         1.3.4      2017-09-16 [1]
##  data.table     1.12.8     2019-12-09 [2]
##  DBI            1.1.0      2019-12-15 [2]
##  dbplyr         2.0.0      2020-11-03 [1]
##  desc           1.2.0      2018-05-01 [2]
##  devtools       2.2.1      2019-09-24 [2]
##  digest         0.6.25     2020-02-23 [1]
##  dplyr        * 1.0.2      2020-08-18 [1]
##  ellipsis       0.3.1      2020-05-15 [1]
##  evaluate       0.14       2019-05-28 [2]
##  fansi          0.4.1      2020-01-08 [2]
##  farver         2.0.3      2020-01-16 [1]
##  fitdistrplus   1.0-14     2019-01-23 [2]
##  forcats      * 0.5.0      2020-03-01 [1]
##  formattable    0.2.0.1    2016-08-05 [1]
##  fs             1.5.0      2020-07-31 [1]
##  future         1.15.1     2019-11-25 [2]
##  future.apply   1.4.0      2020-01-07 [2]
##  gbRd           0.4-11     2012-10-01 [2]
##  gdata          2.18.0     2017-06-06 [2]
##  generics       0.0.2      2018-11-29 [2]
##  ggplot2      * 3.3.2      2020-06-19 [1]
##  ggrepel        0.8.1      2019-05-07 [2]
##  ggridges       0.5.2      2020-01-12 [2]
##  globals        0.12.5     2019-12-07 [2]
##  glue           1.3.2      2020-03-12 [1]
##  gplots         3.0.1.2    2020-01-11 [2]
##  gridExtra      2.3        2017-09-09 [2]
##  gtable         0.3.0      2019-03-25 [2]
##  gtools         3.8.1      2018-06-26 [2]
##  haven          2.3.1      2020-06-01 [1]
##  hms            0.5.3      2020-01-08 [1]
##  htmltools      0.4.0      2019-10-04 [2]
##  htmlwidgets    1.5.1      2019-10-08 [2]
##  httr           1.4.2      2020-07-20 [1]
##  ica            1.0-2      2018-05-24 [2]
##  igraph         1.2.5      2020-03-19 [1]
##  irlba          2.3.3      2019-02-05 [2]
##  jsonlite       1.7.1      2020-09-07 [1]
##  KernSmooth     2.23-16    2019-10-15 [3]
##  knitr          1.26       2019-11-12 [2]
##  labeling       0.3        2014-08-23 [2]
##  lattice        0.20-38    2018-11-04 [3]
##  lazyeval       0.2.2      2019-03-15 [2]
##  leiden         0.3.1      2019-07-23 [2]
##  lifecycle      0.2.0      2020-03-06 [1]
##  listenv        0.8.0      2019-12-05 [2]
##  lmtest         0.9-37     2019-04-30 [2]
##  lsei           1.2-0      2017-10-23 [2]
##  lubridate      1.7.9.2    2020-11-13 [1]
##  magrittr     * 2.0.1      2020-11-17 [1]
##  MASS           7.3-51.5   2019-12-20 [3]
##  Matrix         1.2-18     2019-11-27 [3]
##  memoise        1.1.0      2017-04-21 [2]
##  metap          1.2        2019-12-08 [2]
##  mnormt         1.5-5      2016-10-15 [2]
##  modelr         0.1.8      2020-05-19 [1]
##  multcomp       1.4-12     2020-01-10 [2]
##  multtest       2.42.0     2019-10-29 [2]
##  munsell        0.5.0      2018-06-12 [2]
##  mutoss         0.1-12     2017-12-04 [2]
##  mvtnorm        1.0-12     2020-01-09 [2]
##  nlme           3.1-143    2019-12-10 [3]
##  npsurv         0.4-0      2017-10-14 [2]
##  numDeriv       2016.8-1.1 2019-06-06 [2]
##  pbapply        1.4-2      2019-08-31 [2]
##  pillar         1.4.6      2020-07-10 [1]
##  pkgbuild       1.0.6      2019-10-09 [2]
##  pkgconfig      2.0.3      2019-09-22 [1]
##  pkgload        1.0.2      2018-10-29 [2]
##  plotly         4.9.1      2019-11-07 [2]
##  plotrix        3.7-7      2019-12-05 [2]
##  plyr           1.8.5      2019-12-10 [2]
##  png            0.1-7      2013-12-03 [2]
##  prettyunits    1.1.1      2020-01-24 [1]
##  processx       3.4.2      2020-02-09 [1]
##  progeny      * 1.11.3     2020-10-22 [1]
##  ps             1.3.2      2020-02-13 [1]
##  purrr        * 0.3.4      2020-04-17 [1]
##  R.methodsS3    1.7.1      2016-02-16 [2]
##  R.oo           1.23.0     2019-11-03 [2]
##  R.utils        2.9.2      2019-12-08 [2]
##  R6             2.4.1      2019-11-12 [1]
##  RANN           2.6.1      2019-01-08 [2]
##  rappdirs       0.3.1      2016-03-28 [2]
##  RColorBrewer   1.1-2      2014-12-07 [2]
##  Rcpp           1.0.4      2020-03-17 [1]
##  RcppAnnoy      0.0.16     2020-03-08 [1]
##  RcppParallel   4.4.4      2019-09-27 [2]
##  Rdpack         0.11-1     2019-12-14 [2]
##  readr        * 1.4.0      2020-10-05 [1]
##  readxl       * 1.3.1      2019-03-13 [2]
##  rematch        1.0.1      2016-04-21 [2]
##  remotes        2.1.0      2019-06-24 [2]
##  reprex         0.3.0      2019-05-16 [2]
##  reshape2       1.4.3      2017-12-11 [2]
##  reticulate     1.14       2019-12-17 [2]
##  rlang          0.4.8      2020-10-08 [1]
##  rmarkdown      2.0        2019-12-12 [2]
##  ROCR           1.0-7      2015-03-26 [2]
##  rprojroot      1.3-2      2018-01-03 [2]
##  rstudioapi     0.11       2020-02-07 [1]
##  rsvd           1.0.3      2020-02-17 [1]
##  Rtsne          0.15       2018-11-10 [2]
##  rvest          0.3.6      2020-07-25 [1]
##  sandwich       2.5-1      2019-04-06 [2]
##  scales         1.1.0      2019-11-18 [2]
##  sctransform    0.2.1      2019-12-17 [2]
##  SDMTools       1.1-221.2  2019-11-30 [2]
##  sessioninfo    1.1.1      2018-11-05 [2]
##  Seurat       * 3.1.2      2019-12-12 [2]
##  sn             1.5-4      2019-05-14 [2]
##  stringi        1.5.3      2020-09-09 [1]
##  stringr      * 1.4.0      2019-02-10 [1]
##  survival       3.1-8      2019-12-03 [3]
##  testthat       2.3.2      2020-03-02 [1]
##  TFisher        0.2.0      2018-03-21 [2]
##  TH.data        1.0-10     2019-01-21 [2]
##  tibble       * 3.0.4      2020-10-12 [1]
##  tidyr        * 1.1.2      2020-08-27 [1]
##  tidyselect     1.1.0      2020-05-11 [1]
##  tidyverse    * 1.3.0      2019-11-21 [2]
##  tsne           0.1-3      2016-07-15 [2]
##  usethis        1.5.1      2019-07-04 [2]
##  uwot           0.1.5      2019-12-04 [2]
##  vctrs          0.3.5      2020-11-17 [1]
##  viridis      * 0.5.1      2018-03-29 [2]
##  viridisLite  * 0.3.0      2018-02-01 [2]
##  withr          2.3.0      2020-09-22 [1]
##  xfun           0.12       2020-01-13 [2]
##  xml2           1.3.2      2020-04-23 [1]
##  yaml           2.2.1      2020-02-01 [1]
##  zoo            1.8-7      2020-01-10 [2]
##  source                                 
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.3)                         
##  CRAN (R 3.6.2)                         
##  Bioconductor                           
##  Bioconductor                           
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  Github (clauswilke/colorblindr@1ac3d4d)
##  R-Forge (R 3.6.2)                      
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.3)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.3)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.3)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.3)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  Bioconductor                           
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.3)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  Github (saezlab/progeny@94bea1c)       
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.3)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.3)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.3)                         
##  CRAN (R 3.6.3)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.3)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
##  CRAN (R 3.6.2)                         
## 
## [1] /home/uhlitzf/R/lib
## [2] /usr/local/lib/R/site-library
## [3] /usr/local/lib/R/library